package com.demo2do.jit;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.demo2do.jit.injection.component.ActivityComponent;

public abstract class BaseActivity extends AppCompatActivity {

    private ActivityComponent mActivityComponent;

    LoadingDialog loadingDialog;

    /********* Activity lifecycle ****************************/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    /********* Define BaseActivity methods *********************/

    public ActivityComponent getActivityComponent() {
        if (mActivityComponent == null) {
            mActivityComponent = JitApplication.get(this).getComponent().newActivityComponent();
        }
        return mActivityComponent;
    }

    public void toastShort(final String text) {
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
    }

    /********* Implement base MvpView interface methods ***********/

    public void showLoading(String text) {
        if(loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.changeMessage(text);
        } else {
            loadingDialog = LoadingDialog.show(this, text, true);
        }
    }

    public void hideLoading() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
        }
    }

}
